<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>请假申请</title>
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css">
</head>
<body>
<form class="layui-form" action="/leave/saveLeave" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">请假人</label>
        <div class="layui-input-block">
            <label class="layui-form-label" id="applyUser" name="userId"></label>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">请假天数</label>
        <div class="layui-input-block">
            <input type="text" name="day" required  lay-verify="required" placeholder="请输入天数" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">审批人</label>
        <div class="layui-input-block">
            <select name="approvalUserId" lay-verify="required" id="approvalUser">
                <option value=""></option>
               <!-- <option value="0">北京</option>
                <option value="1">上海</option>
                <option value="2">广州</option>
                <option value="3">深圳</option>
                <option value="4">杭州</option>-->
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formLogin">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="../../plugins/layui/layui.js"></script>
<script src="../../js/root.js"></script>
<script src="../../libs/jquery.min.js"></script>
<script type="text/javascript">
    layui.use(['form','layer','jquery'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        //ajax页面初始化数据
        $.ajax({
            type: "get",
            url: "/leave/leaveApplyInfo",
            async: false,
            dataType:'text',
            success: function (res) {
                res = eval('(' + res + ')');
                if (res.code == '200'){
                    $("#applyUser").text(res.data.applyUser);
                    for (var a = 0; a < res.data.approvalUser.length; a++) {
                        $("#approvalUser").append('<option value="' + res.data.approvalUser[a].id + '">' + res.data.approvalUser[a].userName + '</option>');
                    }
                }else{
                    layer.msg('服务异常，联系后台管理人员。');
                }
            },
            error: function (e) {
                layer.msg(e.msg);
            }
        });

        //渲染表单
        form.render();

        //form表单提交事件
        form.on('submit(formLogin)', function (data) {
            return true; // 返回false 阻止默认 form 跳转
        });
    });
</script>
</body>
</html>